package com.qkst.website.backstage.controller;


import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.qkst.website.backstage.bean.CatgroupBean;
import com.qkst.website.backstage.bean.CatgroupRelPrdBean;
import com.qkst.website.backstage.service.CatgroupService;
import com.qkst.website.common.core.BaseController;

/**
 * @author lh
 * @description 产品目录控制器
 * @date 2017-05-03
 * @email ahlxlihao@163.com
 *
 */
@Controller
@RequestMapping("/backstage/catgroup")
public class CatgroupController extends BaseController{

	@Autowired
	private CatgroupService catgroupService;

	/**
	 * 查询产品目录
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(value = "/list.do", method = { RequestMethod.GET })
	public ModelAndView list(CatgroupBean catgroup) throws IOException{
		ModelAndView mv=this.backstageModelAndView("catgroup/list");
		List<CatgroupBean> catgroupList = catgroupService.list(catgroup);
		mv.addObject("catgroupList", catgroupList);
		return mv;

	}
	
	/**
	 * 添加产品目录
	 * @return
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Map<String, Object> add(CatgroupBean catgroup){
		Map<String, Object> result = new HashMap<String, Object>();
		catgroup=catgroupService.save(catgroup);
		result.put("catgroup", catgroup);
		return result;

	}
	
	/**
	 * 删除产品目录
	 * @return
	 */
	@RequestMapping(value = "/delete.do", method = { RequestMethod.POST })
	@ResponseBody
	public Map<String, Object>  delete(CatgroupBean catgroup){
		Map<String, Object> result = new HashMap<String, Object>();
		boolean flag=catgroupService.delete(catgroup);
		result.put("isSuccess", flag);
		result.put("catgroup", catgroup);
		return result;

	}
	
	/**
	 * 添加产品目录与产品关系
	 * @return
	 */
	@RequestMapping(value = "/addCatgroupRelPrd.do", method = { RequestMethod.POST })
	@ResponseBody
	public Map<String, Object> addCatgroupRelPrd(CatgroupRelPrdBean catgroupRelPrd){
		Map<String, Object> result = new HashMap<String, Object>();
		boolean flag=catgroupService.saveCatgroupRelPrd(catgroupRelPrd);
		result.put("isSuccess", flag);
		result.put("catgroupRelPrd", catgroupRelPrd);
		return result;

	}
	

}
